package com.baizhi.cmfzmanager.service.impl;

import com.baizhi.cmfzmanager.dao.AdminDao;
import com.baizhi.cmfzmanager.entity.Admin;
import com.baizhi.cmfzmanager.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.authc.credential.Md5CredentialsMatcher;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Autowired
    CredentialsMatcher credentialsMatcher;
    @Override
    public Admin login(String username, String password) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<Admin>();
        wrapper.eq("username",username).eq("password",password);
        Admin one = adminDao.selectOne(wrapper);
        return one;
    }

    @Override
    public void regist(String username, String password) {
        String salt="asfa";
        Md5Hash md5Hash = new Md5Hash(password, salt, 1024);
        adminDao.regist(username,md5Hash.toString(),salt);
    }
}
